20. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2023-07-12 04:42:36 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

20.1 Files compared

#LocationFileLast Modified
1Porto v4.0.5/Theme Files/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterCategory.php2022-12-08 01:34:28 +0000
2Porto v4.0.6/Theme Files/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterCategory.php2023-05-05 02:25:46 +0000

20.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged1878
Changed00
Inserted00
Removed00

20.3 Comparison options

WhitespaceConsecutive whitespace is treated as a single space
Character caseDifferences in character case are significant
Line endingsDifferences in line endings (CR and LF characters) are ignored
CR/LF charactersNot shown in the comparison detail
Active line-pairing rules

20.4 Active regular expressions

No regular expressions were active.

20.5 Comparison detail

1 <?php 1 <?php
2 /** 2 /**
3  * Mageplaza 3  * Mageplaza
4  * 4  *
5  * NOTICE OF LICENSE 5  * NOTICE OF LICENSE
6  * 6  *
7  * This source file is subject to the Mageplaza.com license that is 7  * This source file is subject to the Mageplaza.com license that is
8  * available through the world-wide-web at this URL: 8  * available through the world-wide-web at this URL:
9  * https://www.mageplaza.com/LICENSE.txt 9  * https://www.mageplaza.com/LICENSE.txt
10  * 10  *
11  * DISCLAIMER 11  * DISCLAIMER
12  * 12  *
13  * Do not edit or add to this file if you wish to upgrade this extension to newer 13  * Do not edit or add to this file if you wish to upgrade this extension to newer
14  * version in the future. 14  * version in the future.
15  * 15  *
16  * @category    Mageplaza 16  * @category    Mageplaza
17  * @package     Mageplaza_LayeredNavigation 17  * @package     Mageplaza_LayeredNavigation
18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/) 18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
19  * @license     https://www.mageplaza.com/LICENSE.txt 19  * @license     https://www.mageplaza.com/LICENSE.txt
20  */ 20  */
21  21 
22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; 22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter;
23  23 
24 use Magento\Catalog\Api\CategoryManagementInterface; 24 use Magento\Catalog\Api\CategoryManagementInterface;
25 use Magento\Catalog\Api\Data\CategoryTreeInterface; 25 use Magento\Catalog\Api\Data\CategoryTreeInterface;
26 use Magento\Catalog\Api\ProductAttributeRepositoryInterface; 26 use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
27 use Magento\Catalog\Model\Layer as LayerCatalog; 27 use Magento\Catalog\Model\Layer as LayerCatalog;
28 use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory; 28 use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory;
29 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; 29 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
30 use Magento\Catalog\Model\Layer\Filter\ItemFactory; 30 use Magento\Catalog\Model\Layer\Filter\ItemFactory;
31 use Magento\Catalog\Model\ResourceModel\Eav\Attribute; 31 use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
32 use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter; 32 use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter;
33 use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection; 33 use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
34 use Magento\Framework\App\RequestInterface; 34 use Magento\Framework\App\RequestInterface;
35 use Magento\Framework\Escaper; 35 use Magento\Framework\Escaper;
36 use Magento\Framework\Exception\LocalizedException; 36 use Magento\Framework\Exception\LocalizedException;
37 use Magento\Framework\Exception\NoSuchEntityException; 37 use Magento\Framework\Exception\NoSuchEntityException;
38 use Magento\Framework\Exception\StateException; 38 use Magento\Framework\Exception\StateException;
39 use Magento\Store\Model\StoreManagerInterface; 39 use Magento\Store\Model\StoreManagerInterface;
40 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; 40 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper;
41 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\CategoriesLevel; 41 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\CategoriesLevel;
42 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\RenderCategoryTree; 42 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\RenderCategoryTree;
43  43 
44 /** 44 /**
45  * Class Category 45  * Class Category
46  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter 46  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter
47  */ 47  */
48 class Category extends AbstractFilter 48 class Category extends AbstractFilter
49 { 49 {
50     /** @var LayerHelper */ 50     /** @var LayerHelper */
51     protected $_moduleHelper; 51     protected $_moduleHelper;
52  52 
53     /** @var bool Is Filterable Flag */ 53     /** @var bool Is Filterable Flag */
54     protected $_isFilter = false; 54     protected $_isFilter = false;
55  55 
56     /** @var Escaper */ 56     /** @var Escaper */
57     private $escaper; 57     private $escaper;
58  58 
59     /** @var  LayerCatalog\Filter\DataProvider\Category */ 59     /** @var  LayerCatalog\Filter\DataProvider\Category */
60     private $dataProvider; 60     private $dataProvider;
61     /** 61     /**
62      * @var ProductAttributeRepositoryInterface 62      * @var ProductAttributeRepositoryInterface
63      */ 63      */
64     protected $attributeRepository; 64     protected $attributeRepository;
65     /** 65     /**
66      * @var CategoryManagementInterface 66      * @var CategoryManagementInterface
67      */ 67      */
68     protected $categoryManagement; 68     protected $categoryManagement;
69  69 
70     /** 70     /**
71      * @var Attribute 71      * @var Attribute
72      */ 72      */
73     protected $attributeData; 73     protected $attributeData;
74  74 
75     protected $isFullCategoryTree = false; 75     protected $isFullCategoryTree = false;
76     /** 76     /**
77      * @var Item\DataBuilder 77      * @var Item\DataBuilder
78      */ 78      */
79     protected $layerDataBuilder; 79     protected $layerDataBuilder;
80     /** 80     /**
81      * @var CategoryItemFactory 81      * @var CategoryItemFactory
82      */ 82      */
83     protected $categoryItemFactory; 83     protected $categoryItemFactory;
84  84 
85     /** 85     /**
86      * Category constructor. 86      * Category constructor.
87      * 87      *
88      * @param ItemFactory $filterItemFactory 88      * @param ItemFactory $filterItemFactory
89      * @param StoreManagerInterface $storeManager 89      * @param StoreManagerInterface $storeManager
90      * @param LayerCatalog $layer 90      * @param LayerCatalog $layer
91      * @param DataBuilder $itemDataBuilder 91      * @param DataBuilder $itemDataBuilder
92      * @param Escaper $escaper 92      * @param Escaper $escaper
93      * @param CategoryFactory $dataProviderFactory 93      * @param CategoryFactory $dataProviderFactory
94      * @param LayerHelper $moduleHelper 94      * @param LayerHelper $moduleHelper
95      * @param ProductAttributeRepositoryInterface $attributeRepository 95      * @param ProductAttributeRepositoryInterface $attributeRepository
96      * @param CategoryManagementInterface $categoryManagement 96      * @param CategoryManagementInterface $categoryManagement
97      * @param Item\DataBuilder $layerDataBuilder 97      * @param Item\DataBuilder $layerDataBuilder
98      * @param CategoryItemFactory $categoryItemFactory 98      * @param CategoryItemFactory $categoryItemFactory
99      * @param array $data 99      * @param array $data
100      * 100      *
101      * @throws LocalizedException 101      * @throws LocalizedException
102      */ 102      */
103     public function __construct( 103     public function __construct(
104         ItemFactory $filterItemFactory, 104         ItemFactory $filterItemFactory,
105         StoreManagerInterface $storeManager, 105         StoreManagerInterface $storeManager,
106         LayerCatalog $layer, 106         LayerCatalog $layer,
107         DataBuilder $itemDataBuilder, 107         DataBuilder $itemDataBuilder,
108         Escaper $escaper, 108         Escaper $escaper,
109         CategoryFactory $dataProviderFactory, 109         CategoryFactory $dataProviderFactory,
110         LayerHelper $moduleHelper, 110         LayerHelper $moduleHelper,
111         ProductAttributeRepositoryInterface $attributeRepository, 111         ProductAttributeRepositoryInterface $attributeRepository,
112         CategoryManagementInterface $categoryManagement, 112         CategoryManagementInterface $categoryManagement,
113         Item\DataBuilder $layerDataBuilder, 113         Item\DataBuilder $layerDataBuilder,
114         CategoryItemFactory $categoryItemFactory, 114         CategoryItemFactory $categoryItemFactory,
115         array $data = [] 115         array $data = []
116     ) { 116     ) {
117         parent::__construct( 117         parent::__construct(
118             $filterItemFactory, 118             $filterItemFactory,
119             $storeManager, 119             $storeManager,
120             $layer, 120             $layer,
121             $itemDataBuilder, 121             $itemDataBuilder,
122             $escaper, 122             $escaper,
123             $dataProviderFactory, 123             $dataProviderFactory,
124             $data 124             $data
125         ); 125         );
126  126 
127         $this->escaper             = $escaper; 127         $this->escaper             = $escaper;
128         $this->_moduleHelper       = $moduleHelper; 128         $this->_moduleHelper       = $moduleHelper;
129         $this->dataProvider        = $dataProviderFactory->create(['layer' => $this->getLayer()]); 129         $this->dataProvider        = $dataProviderFactory->create(['layer' => $this->getLayer()]);
130         $this->attributeRepository = $attributeRepository; 130         $this->attributeRepository = $attributeRepository;
131         $this->categoryManagement  = $categoryManagement; 131         $this->categoryManagement  = $categoryManagement;
132         $this->layerDataBuilder    = $layerDataBuilder; 132         $this->layerDataBuilder    = $layerDataBuilder;
133         $this->categoryItemFactory = $categoryItemFactory; 133         $this->categoryItemFactory = $categoryItemFactory;
134     } 134     }
135  135 
136     /** 136     /**
137      * @inheritdoc 137      * @inheritdoc
138      */ 138      */
139     public function apply(RequestInterface $request) 139     public function apply(RequestInterface $request)
140     { 140     {
141         if (!$this->_moduleHelper->isEnabled()) { 141         if (!$this->_moduleHelper->isEnabled()) {
142             return parent::apply($request); 142             return parent::apply($request);
143         } 143         }
144  144 
145         $categoryId = $request->getParam($this->_requestVar); 145         $categoryId = $request->getParam($this->_requestVar);
146         if (empty($categoryId) && $this->isRenderCategoryTree() && $this->isFullCategoryTree) { 146         if (empty($categoryId) && $this->isRenderCategoryTree() && $this->isFullCategoryTree) {
147             $request->setParam($this->_requestVar, $this->dataProvider->getCategory()->getId()); 147             $request->setParam($this->_requestVar, $this->dataProvider->getCategory()->getId());
148             $categoryId = $request->getParam($this->_requestVar); 148             $categoryId = $request->getParam($this->_requestVar);
149         } 149         }
150         if (empty($categoryId)) { 150         if (empty($categoryId)) {
151             return $this; 151             return $this;
152         } 152         }
153  153 
154         $categoryIds = []; 154         $categoryIds = [];
155         $categoryId = explode(',', $categoryId); 155         $categoryId = explode(',', $categoryId);
156         $categoryId = array_unique($categoryId); 156         $categoryId = array_unique($categoryId);
157         foreach ($categoryId as $id) { 157         foreach ($categoryId as $id) {
158             $this->dataProvider->setCategoryId($id); 158             $this->dataProvider->setCategoryId($id);
159             if ($this->dataProvider->isValid()) { 159             if ($this->dataProvider->isValid()) {
160                 $category = $this->dataProvider->getCategory(); 160                 $category = $this->dataProvider->getCategory();
161                 if ($this->isRenderCategoryTree()) { 161                 if ($this->isRenderCategoryTree()) {
162                     $categoryIds[] = $id; 162                     $categoryIds[] = $id;
163                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); 163                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id));
164                 } elseif ($request->getParam('id') !== $id) { 164                 } elseif ($request->getParam('id') !== $id) {
165                     $categoryIds[] = $id; 165                     $categoryIds[] = $id;
166                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); 166                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id));
167                 } 167                 }
168             } 168             }
169         } 169         }
170  170 
171         if (!empty($categoryIds)) { 171         if (!empty($categoryIds)) {
172             $this->_isFilter = true; 172             $this->_isFilter = true;
173             if ($this->isRenderCategoryTree() && $this->isFullCategoryTree) { 173             if ($this->isRenderCategoryTree() && $this->isFullCategoryTree) {
174                 $this->getLayer()->getProductCollection()->resetCategoryIds($this->getCurrentCategoryId()) 174                 $this->getLayer()->getProductCollection()->resetCategoryIds($this->getCurrentCategoryId())
175                     ->resetCategoryFilter($this->getCurrentCategoryId())->addLayerCategoryFilter($categoryIds); 175                     ->resetCategoryFilter($this->getCurrentCategoryId())->addLayerCategoryFilter($categoryIds);
176             } else { 176             } else {
177                 $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds); 177                 $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds);
178             } 178             }
179         } 179         }
180  180 
181         if ($parentCategoryId = $request->getParam('id')) { 181         if ($parentCategoryId = $request->getParam('id')) {
182             $this->dataProvider->setCategoryId($parentCategoryId); 182             $this->dataProvider->setCategoryId($parentCategoryId);
183         } 183         }
184  184 
185         return $this; 185         return $this;
186     } 186     }
187  187 
188     /** 188     /**
189      * @inheritDoc 189      * @inheritDoc
190      */ 190      */
191     protected function _initItems() 191     protected function _initItems()
192     { 192     {
193         if (!$this->_moduleHelper->isEnabled()) { 193         if (!$this->_moduleHelper->isEnabled()) {
194             return parent::_initItems(); 194             return parent::_initItems();
195         } 195         }
196  196 
197         if ($this->isRenderCategoryTree()) { 197         if ($this->isRenderCategoryTree()) {
198             $data = $this->getCategoryAdditionData(); 198             $data = $this->getCategoryAdditionData();
199             /** @var CategoryItem $itemCollection */ 199             /** @var CategoryItem $itemCollection */
200             $itemCollection = $this->categoryItemFactory->create(); 200             $itemCollection = $this->categoryItemFactory->create();
201             if ($data && $data['count']) { 201             if ($data && $data['count']) {
202                 $itemCollection->setStartPath($data['startPath']); 202                 $itemCollection->setStartPath($data['startPath']);
203                 $itemCollection->setCount($data['count']); 203                 $itemCollection->setCount($data['count']);
204                 foreach ($data['items'] as $parentId => $items) { 204                 foreach ($data['items'] as $parentId => $items) {
205                     foreach ($items as $item) { 205                     foreach ($items as $item) {
206                         $itemCollection->addItem( 206                         $itemCollection->addItem(
207                             $item['parent_id'], 207                             $item['parent_id'],
208                             $this->_createItem($item['label'], $item['value'], $item['count']) 208                             $this->_createItem($item['label'], $item['value'], $item['count'])
209                         ); 209                         );
210                     } 210                     }
211                 } 211                 }
212             } 212             }
213  213 
214             $this->_items = $itemCollection; 214             $this->_items = $itemCollection;
215  215 
216             return $this; 216             return $this;
217         } 217         }
218  218 
219         return parent::_initItems(); 219         return parent::_initItems();
220     } 220     }
221  221 
222     /** 222     /**
223      * @return array 223      * @return array
224      * @throws StateException 224      * @throws StateException
225      */ 225      */
226     protected function _getItemsData() 226     protected function _getItemsData()
227     { 227     {
228         if (!$this->_moduleHelper->isEnabled()) { 228         if (!$this->_moduleHelper->isEnabled()) {
229             return parent::_getItemsData(); 229             return parent::_getItemsData();
230         } 230         }
231  231 
232         /** @var Collection $productCollection */ 232         /** @var Collection $productCollection */
233         $productCollection = $this->getLayer()->getProductCollection(); 233         $productCollection = $this->getLayer()->getProductCollection();
234  234 
235         if ($this->_isFilter) { 235         if ($this->_isFilter) {
236             $productCollection = $productCollection->getCollectionClone() 236             $productCollection = $productCollection->getCollectionClone()
237                 ->removeAttributeSearch('category_ids'); 237                 ->removeAttributeSearch('category_ids');
238         } 238         }
239  239 
240         $optionsFacetedData = $productCollection->getFacetedData('category'); 240         $optionsFacetedData = $productCollection->getFacetedData('category');
241         $category           = $this->dataProvider->getCategory(); 241         $category           = $this->dataProvider->getCategory();
242         $categories         = $category->getChildrenCategories(); 242         $categories         = $category->getChildrenCategories();
243  243 
244         $collectionSize = $productCollection->getSize(); 244         $collectionSize = $productCollection->getSize();
245  245 
246         if ($category->getIsActive()) { 246         if ($category->getIsActive()) {
247             foreach ($categories as $childCategory) { 247             foreach ($categories as $childCategory) {
248                 $count = isset($optionsFacetedData[$childCategory->getId()]) 248                 $count = isset($optionsFacetedData[$childCategory->getId()])
249                     ? $optionsFacetedData[$childCategory->getId()]['count'] : 0; 249                     ? $optionsFacetedData[$childCategory->getId()]['count'] : 0;
250                 if ($childCategory->getIsActive() 250                 if ($childCategory->getIsActive()
251                     && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize) 251                     && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize)
252                 ) { 252                 ) {
253                     $this->itemDataBuilder->addItemData( 253                     $this->itemDataBuilder->addItemData(
254                         $this->escaper->escapeHtml($childCategory->getName()), 254                         $this->escaper->escapeHtml($childCategory->getName()),
255                         $childCategory->getId(), 255                         $childCategory->getId(),
256                         $count 256                         $count
257                     ); 257                     );
258                 } 258                 }
259             } 259             }
260         } 260         }
261  261 
262         return $this->itemDataBuilder->build(); 262         return $this->itemDataBuilder->build();
263     } 263     }
264  264 
265     /** 265     /**
266      * @return array 266      * @return array
267      * @throws LocalizedException 267      * @throws LocalizedException
268      * @throws NoSuchEntityException 268      * @throws NoSuchEntityException
269      */ 269      */
270     protected function getCategoryAdditionData() 270     protected function getCategoryAdditionData()
271     { 271     {
272         $attributeModel     = $this->getCategoryAttributeModel(); 272         $attributeModel     = $this->getCategoryAttributeModel();
273         $renderCategoryTree = $attributeModel->getData('render_category_tree'); 273         $renderCategoryTree = $attributeModel->getData('render_category_tree');
274         $itemsData          = []; 274         $itemsData          = [];
275         $startPath          = ''; 275         $startPath          = '';
276  276 
277         try { 277         try {
278             $optionsFacetedData = $this->getFacetedData(); 278             $optionsFacetedData = $this->getFacetedData();
279             if (empty($optionsFacetedData)) { 279             if (empty($optionsFacetedData)) {
280                 $categoryId                      = $this->dataProvider->getCategory()->getId(); 280                 $categoryId                      = $this->dataProvider->getCategory()->getId();
281                 $optionsFacetedData[$categoryId] = [ 281                 $optionsFacetedData[$categoryId] = [
282                     'value' => $categoryId, 282                     'value' => $categoryId,
283                     'count' => $this->getLayer()->getProductCollection()->getSize() 283                     'count' => $this->getLayer()->getProductCollection()->getSize()
284                 ]; 284                 ];
285             } 285             }
286         } catch (StateException $e) { 286         } catch (StateException $e) {
287             return []; 287             return [];
288         } 288         }
289  289 
290         try { 290         try {
291             $depth            = $renderCategoryTree !== RenderCategoryTree::FULL_CATEGORY 291             $depth            = $renderCategoryTree !== RenderCategoryTree::FULL_CATEGORY
292                 ? $attributeModel->getData('category_tree_depth') 292                 ? $attributeModel->getData('category_tree_depth')
293                 : null; 293                 : null;
294             $categoryTreeList = $this->categoryManagement->getTree($this->getCurrentCategoryId(), $depth); 294             $categoryTreeList = $this->categoryManagement->getTree($this->getCurrentCategoryId(), $depth);
295         } catch (NoSuchEntityException $e) { 295         } catch (NoSuchEntityException $e) {
296             $categoryTreeList = []; 296             $categoryTreeList = [];
297         } 297         }
298  298 
299         if ($categoryTreeList) { 299         if ($categoryTreeList) {
300             if ($renderCategoryTree === RenderCategoryTree::CUSTOM 300             if ($renderCategoryTree === RenderCategoryTree::CUSTOM
301                 && $attributeModel->getData('categories_level') === CategoriesLevel::CURRENT_CATEGORY 301                 && $attributeModel->getData('categories_level') === CategoriesLevel::CURRENT_CATEGORY
302             ) { 302             ) {
303                 $startPath = $categoryTreeList->getParentId(); 303                 $startPath = $categoryTreeList->getParentId();
304                 $count     = isset($optionsFacetedData[$categoryTreeList->getId()]) 304                 $count     = isset($optionsFacetedData[$categoryTreeList->getId()])
305                     ? $optionsFacetedData[$categoryTreeList->getId()]['count'] : 0; 305                     ? $optionsFacetedData[$categoryTreeList->getId()]['count'] : 0;
306  306 
307                 $this->layerDataBuilder->addItemData( 307                 $this->layerDataBuilder->addItemData(
308                     $this->escaper->escapeHtml($categoryTreeList->getName()), 308                     $this->escaper->escapeHtml($categoryTreeList->getName()),
309                     $categoryTreeList->getId(), 309                     $categoryTreeList->getId(),
310                     $categoryTreeList->getParentId(), 310                     $categoryTreeList->getParentId(),
311                     $categoryTreeList->getPosition(), 311                     $categoryTreeList->getPosition(),
312                     $categoryTreeList->getLevel(), 312                     $categoryTreeList->getLevel(),
313                     $count 313                     $count
314                 ); 314                 );
315             } else { 315             } else {
316                 $startPath = $categoryTreeList->getId(); 316                 $startPath = $categoryTreeList->getId();
317             } 317             }
318             $this->getCategoryTree($categoryTreeList, $optionsFacetedData); 318             $this->getCategoryTree($categoryTreeList, $optionsFacetedData);
319         } 319         }
320         $itemsData['startPath'] = $startPath; 320         $itemsData['startPath'] = $startPath;
321         $itemsData['count']     = $this->layerDataBuilder->getCount(); 321         $itemsData['count']     = $this->layerDataBuilder->getCount();
322         $itemsData['items']     = $this->layerDataBuilder->build(); 322         $itemsData['items']     = $this->layerDataBuilder->build();
323  323 
324         return $itemsData; 324         return $itemsData;
325     } 325     }
326  326 
327     /** 327     /**
328      * @return bool 328      * @return bool
329      * @throws NoSuchEntityException 329      * @throws NoSuchEntityException
330      */ 330      */
331     public function isRenderCategoryTree() 331     public function isRenderCategoryTree()
332     { 332     {
333         $attributeModel     = $this->getCategoryAttributeModel(); 333         $attributeModel     = $this->getCategoryAttributeModel();
334         $renderCategoryTree = $attributeModel->getData('render_category_tree'); 334         $renderCategoryTree = $attributeModel->getData('render_category_tree');
335  335 
336         if ($renderCategoryTree === RenderCategoryTree::FULL_CATEGORY) { 336         if ($renderCategoryTree === RenderCategoryTree::FULL_CATEGORY) {
337             $this->isFullCategoryTree = true; 337             $this->isFullCategoryTree = true;
338         } elseif ($renderCategoryTree === RenderCategoryTree::CUSTOM 338         } elseif ($renderCategoryTree === RenderCategoryTree::CUSTOM
339             && $attributeModel->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY) { 339             && $attributeModel->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY) {
340             $this->isFullCategoryTree = true; 340             $this->isFullCategoryTree = true;
341         } 341         }
342  342 
343         return $renderCategoryTree && $renderCategoryTree !== RenderCategoryTree::NO; 343         return $renderCategoryTree && $renderCategoryTree !== RenderCategoryTree::NO;
344     } 344     }
345  345 
346     /** 346     /**
347      * @param CategoryTreeInterface $tree 347      * @param CategoryTreeInterface $tree
348      * @param array $optionsFacetedData 348      * @param array $optionsFacetedData
349      */ 349      */
350     public function getCategoryTree($tree, $optionsFacetedData) 350     public function getCategoryTree($tree, $optionsFacetedData)
351     { 351     {
352         if (!$tree) { 352         if (!$tree) {
353             return; 353             return;
354         } 354         }
355  355 
356         foreach ($tree->getChildrenData() as $item) { 356         foreach ($tree->getChildrenData() as $item) {
357             $count = isset($optionsFacetedData[$item->getId()]) 357             $count = isset($optionsFacetedData[$item->getId()])
358                 ? $optionsFacetedData[$item->getId()]['count'] : 0; 358                 ? $optionsFacetedData[$item->getId()]['count'] : 0;
359  359 
360             if ($item->getIsActive() === '1') { 360             if ($item->getIsActive() === '1') {
361                 $child = $item->getChildrenData(); 361                 $child = $item->getChildrenData();
362                 if ($item->getLevel() !== '1') { 362                 if ($item->getLevel() !== '1') {
363                     $this->layerDataBuilder->addItemData( 363                     $this->layerDataBuilder->addItemData(
364                         $this->escaper->escapeHtml($item->getName()), 364                         $this->escaper->escapeHtml($item->getName()),
365                         $item->getId(), 365                         $item->getId(),
366                         $item->getParentId(), 366                         $item->getParentId(),
367                         $item->getPosition(), 367                         $item->getPosition(),
368                         $item->getLevel(), 368                         $item->getLevel(),
369                         $count 369                         $count
370                     ); 370                     );
371                 } 371                 }
372  372 
373                 if ($child) { 373                 if ($child) {
374                     $this->getCategoryTree($item, $optionsFacetedData); 374                     $this->getCategoryTree($item, $optionsFacetedData);
375                 } 375                 }
376             } 376             }
377         } 377         }
378     } 378     }
379  379 
380     /** 380     /**
381      * @return int|null 381      * @return int|null
382      * @throws LocalizedException 382      * @throws LocalizedException
383      * @throws NoSuchEntityException 383      * @throws NoSuchEntityException
384      */ 384      */
385     protected function getCurrentCategoryId() 385     protected function getCurrentCategoryId()
386     { 386     {
387         if ($this->isFullCategoryTree) { 387         if ($this->isFullCategoryTree) {
388             $categoryId = $this->_storeManager->getStore()->getRootCategoryId(); 388             $categoryId = $this->_storeManager->getStore()->getRootCategoryId();
389         } else { 389         } else {
390             $categoryId = $this->getCategoryAttributeModel()->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY 390             $categoryId = $this->getCategoryAttributeModel()->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY
391                 ? $this->_storeManager->getStore()->getRootCategoryId() 391                 ? $this->_storeManager->getStore()->getRootCategoryId()
392                 : $this->dataProvider->getCategory()->getId(); 392                 : $this->dataProvider->getCategory()->getId();
393         } 393         }
394  394 
395         return $categoryId; 395         return $categoryId;
396     } 396     }
397  397 
398     /** 398     /**
399      * @return array 399      * @return array
400      * @throws LocalizedException 400      * @throws LocalizedException
401      * @throws NoSuchEntityException 401      * @throws NoSuchEntityException
402      * @throws StateException 402      * @throws StateException
403      */ 403      */
404     protected function getFacetedData() 404     protected function getFacetedData()
405     { 405     {
406         /** @var Collection $productCollection */ 406         /** @var Collection $productCollection */
407         $productCollection = $this->getLayer()->getProductCollection(); 407         $productCollection = $this->getLayer()->getProductCollection();
408  408 
409         if ($this->_isFilter) { 409         if ($this->_isFilter) {
410             $productCollection = $productCollection->getCollectionClone() 410             $productCollection = $productCollection->getCollectionClone()
411                 ->removeAttributeSearch('category_ids'); 411                 ->removeAttributeSearch('category_ids');
412         } else { 412         } else {
413             $productCollection = $productCollection->getCollectionClone() 413             $productCollection = $productCollection->getCollectionClone()
414                 ->setCategoryFilter($this->getCurrentCategoryId()); 414                 ->setCategoryFilter($this->getCurrentCategoryId());
415         } 415         }
416  416 
417         return $productCollection->getFacetedData('category'); 417         return $productCollection->getFacetedData('category');
418     } 418     }
419  419 
420     /** 420     /**
421      * @return Attribute 421      * @return Attribute
422      * @throws NoSuchEntityException 422      * @throws NoSuchEntityException
423      */ 423      */
424     public function getCategoryAttributeModel() 424     public function getCategoryAttributeModel()
425     { 425     {
426         if (!$this->attributeData) { 426         if (!$this->attributeData) {
427             /** @var Attribute $attribute */ 427             /** @var Attribute $attribute */
428             $this->attributeData = $this->attributeRepository->get('category_ids'); 428             $this->attributeData = $this->attributeRepository->get('category_ids');
429             if ($this->attributeData->getId() && $data = $this->attributeData->getAdditionalData()) { 429             if ($this->attributeData->getId() && $data = $this->attributeData->getAdditionalData()) {
430                 $additionalData = $this->_moduleHelper->unserialize($data); 430                 $additionalData = $this->_moduleHelper->unserialize($data);
431                 if (is_array($additionalData)) { 431                 if (is_array($additionalData)) {
432                     $this->attributeData->addData($additionalData); 432                     $this->attributeData->addData($additionalData);
433                 } 433                 }
434             } 434             }
435         } 435         }
436  436 
437         return $this->attributeData; 437         return $this->attributeData;
438     } 438     }
439 } 439 }